//
//  KLHttpAPI.h
//  KISSLOCK
//
//  Created by 陈宾鹏 on 16/4/21.
//  Copyright © 2016年 陈宾鹏. All rights reserved.
//  第三方框架MKNetWorkKi的使用
// http://blog.csdn.net/lookyou111/article/details/26450663

//通过http协议从服务器获取相关数据
#import <Foundation/Foundation.h>
#import "HemaConst.h"
#import "MKNetworkKit.h"

//服务器ip地址
//#define HTTP_SERVER_ADDRESS @"192.168.0.110:8888" //内网
//#define HTTP_SERVER_ADDRESS @"211.149.247.174:8888" //虚拟机
//#define HTTP_SERVER_ADDRESS @"192.168.0.254:8888"//新接口
//#define HTTP_SERVER_ADDRESS @"guoyang.ddnsfree.com:50080" //测试环境
//#define HTTP_SERVER_ADDRESS @"www.kisslock.org:8888" //云服务器
// hm_kisslockcloud/index.php/Webservice/V100
//#define HTTP_SERVER_ADDRESS @"192.168.0.241" //2.0新接口

#define HTTP_SERVER_ADDRESS @"192.168.0.240" //

@interface KLHttpAPI : NSObject
// 获取token
+ (void) requestGetTokenWithUsername:(NSString *)username
                               password:(NSString *)password
                      completionHandler:(void (^)(NSString *responseString))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler;

// 登录
+ (void) requestLoginResultWithUsername:(NSString *)username
                            password:(NSString *)password
                    completionHandler:(void (^)(NSString *responseString))completionHandler
                         errorHandler:(void (^)(NSString *error))errorHandler;

// 注册
+ (void) requestRegisterResultWithUserName:(NSString *)name
                             password:(NSString *)password
                             phoneNumber:(NSString *)phoneNumber
                               temp_token:(NSString *)temp_token
                    completionHandler:(void (^)(NSString *responseString))completionHandler
                         errorHandler:(void (^)(NSString *error))errorHandler;

// 找回密码
+ (void) findBackPasswordWithKeyType:(NSString *)keyType
                            new_password:(NSString *)newPassword
                            temp_token:(NSString *)temp_token
                                completionHandler:(void (^)(NSString *responseString))completionHandler
                                      errorHandler:(void (^)(NSString *error))errorHandler;

// 获取验证码
+ (void) requestSecurityCodeWithUserName:(NSString *)userName
                                   type:(NSString *)type
                  completionHandler:(void (^)(NSString *responseString))completionHandler
                       errorHandler:(void (^)(NSString *error))errorHandler;

//验证随机码服务
+ (void) requestCheckSecurityCodeWithUserName:(NSString *)userName
                                securityCode:(NSString *)code
                           completionHandler:(void (^)(NSString *responseString))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler;

//提交个人信息
+ (void) submitUserInformationWithUserDic:(NSDictionary *)userInforDic
                           completionHandler:(void (^)(NSString *responseString))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler;

//获取个人信息
+ (void) requestUserInformationWithToken:(NSString *)token
                                 userID:(NSString *)userID
                      completionHandler:(void (^)(NSString *responseString))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler;

//上传图片
+ (void) submitImageDataWithToken:(NSString *)token
                       imageData:(NSData *)imageData
                         keyType:(NSString *)keyType
                      completionHandler:(void (^)(NSString *responseString))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler;

//更换手机号
+ (void) requestChangeMobileWithToken:(NSString *)token
                      newPhoneNumber:(NSString *)phoneNumber
                   completionHandler:(void (^)(NSString *responseString))completionHandler
                        errorHandler:(void (^)(NSString *error))errorHandler;

//修改密码
+ (void) requestChangePasswordToken:(NSString *)token
                           keytype:(NSString *)keytype
                       oldPassword:(NSString *)old_password
                       newPassword:(NSString *)new_password
                 completionHandler:(void (^)(NSString *responseString))completionHandler
                      errorHandler:(void (^)(NSString *error))errorHandler;

//扫描二维码添加锁
+ (void) requestAddLockWithLockName:(NSString *)lockName
                          lockUname:(NSString *)lockUname
                               code:(NSString *)code
                 completionHandler:(void (^)(NSString *responseString))completionHandler
                      errorHandler:(void (^)(NSString *error))errorHandler;

//添加子钥匙
+ (void) requestAddChildKeyWithLock_id:(NSString *)lock_id
                             mobiel:(NSString *)mobiel
                              keyType:(NSString *)type
                            startdate:(NSString *)startdate
                              enddate:(NSString *)enddate
                                 days:(NSString *)days
                             totalfee:(NSString *)totalfee
                              content:(NSString *)content
                          dataPackage:(NSString *)key_str
                                token:(NSString *)token
                    completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                         errorHandler:(void (^)(NSString *error))errorHandler;

//获取锁列表
+ (void) requestLockListWith:(NSString *)token
           completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                errorHandler:(void (^)(NSString *error))errorHandler;

//获取钥匙列表
+ (void) requestKeyListWith:(NSString *)token
          completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
               errorHandler:(void (^)(NSString *error))errorHandler;

//给服务器上传锁返回信息
+ (void) uploadLockBackInfoToServer:(NSMutableArray *)openlockinfor
                 completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                      errorHandler:(void (^)(NSString *error))errorHandler;

//修改锁别名
+ (void) convertLockUnameToNameWithLockID:(NSString *)lock_id
                                   alias:(NSString *)second_name
                       completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                            errorHandler:(void (^)(NSString *error))errorHandler;

//修改子钥匙别名
+ (void) reviseChildKeyNameWithKeyID:(NSString *)key_id
                               alias:(NSString *)second_name
                   completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                        errorHandler:(void (^)(NSString *error))errorHandler;

//修改锁地址
+ (void) editLockAddressWithLockID:(NSString *)lock_id
                           address:(NSString *)address
                 completionHandler:(void (^)(NSDictionary *responseDic))completionHandler
                      errorHandler:(void (^)(NSString *error))errorHandler;

//获取子钥匙价格
+ (void)requestGetChild_KeyPriceWithStartDate:(NSString *)startdate
                                      endDate:(NSString *)enddate
                          completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                               errorHandler:(void (^)(NSString *error))errorHandler;

//获取委托价格
+ (void) requestGetGrant_lock_priceWithCompletionHandler:(void (^)(MKNetworkOperation *operation))      completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler;

//分发子钥匙
+ (void) distributeChild_keyWithLockID:(NSString *)lock_id
                                mobile:(NSString *)mobile
                             startdate:(NSString *)startdate
                               enddate:(NSString *)enddate
                              totalfee:(NSString *)totalfee
                              rsa_data:(NSString *)rsa_data
                                 style:(NSString *)style
                           from_key_id:(NSString *)from_key_id
                                AESkey:(NSString *)AESkey
                                 power:(NSString *)power
                            updatetime:(NSString *)updatetime
                                 token:(NSString *)token
                           commondCode:(NSString *)Command_code
                     completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                          errorHandler:(void (^)(NSString *error))errorHandler;

//删除到期子钥匙
+ (void) removeOutOfDateChildKeyWithToken:(NSString *)token
                                   key_id:(NSString *)key_id
                        completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                             errorHandler:(void (^)(NSString *error))errorHandler;

//删除所有临时钥匙
+ (void) removeAllTemporaryKeyWithToken:(NSString *)token
                                lock_id:(NSString *)lock_id
                      completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler;

//发送委托管理命令
+ (void) sendDelegateCommondWithLock_id:(NSString *)lock_id
                                 mobile:(NSString *)mobile
                        command_content:(NSString *)command_content
                                   type:(NSString *)type
                                apptime:(NSString *)apptime
                           commond_data:(NSString *)commond_data
                               totalfee:(NSString *)totalfee
                        completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                            errorHandler:(void (^)(NSString *error))errorHandler;

//获取所有的委托命令
+ (void) getCommondListWithToken:(NSString *)token
               completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                    errorHandler:(void (^)(NSString *error))errorHandler;

//执行委托命令成功返回服务器
+ (void) implementCommondSuccessWithCommondId:(NSString *)command_id
                            completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                 errorHandler:(void (^)(NSString *error))errorHandler;

//发送钥匙串
+ (void) sendKeysGroupWithLockArray:(NSMutableArray *)lockArray
                            keytype:(NSString *)keytype
                           trade_no:(NSString *)trade_no
                           totalfee:(NSString *)totalfee
                  completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                       errorHandler:(void (^)(NSString *error))errorHandler;

//充值或支付成功
+ (void) payoffSuccessWithKeytype:(NSString *)keytype
                        total_fee:(NSString *)totalfee
                         trade_no:(NSString *)tradeNo
                completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                     errorHandler:(void (^)(NSString *error))errorHandler;

//提现申请
+ (void) cashRequestWithApplyfee:(NSString *)applyfee
                     paypassword:(NSString *)paypassword
                         keytype:(NSString *)keytype
               completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                    errorHandler:(void (^)(NSString *error))errorHandler;

//用户支付宝保存
+ (void) saveUsersAliAccountWithAliuser:(NSString *)aliuser
                            aliNickName:(NSString *)nickname
                      completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler;

//设置支付密码
+ (void) setPayPasswordWithPassword:(NSString *)paypassword
                  completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                       errorHandler:(void (^)(NSString *error))errorHandler;

//检测是否设置了支付密码 
+ (void) checkIsExitPaypwdCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                   errorHandler:(void (^)(NSString *error))errorHandler;

//获取金额明细
+ (void) requestAccounListWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                   errorHandler:(void (^)(NSString *error))errorHandler;

//获取余额
+ (void) requestBalanceWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler;

//获取开锁记录
+ (void) requestOpenLockHistroryWithLockID:(NSString *)lock_id
                                  page_num:(NSString *)page_num
                         completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                              errorHandler:(void (^)(NSString *error))errorHandler;

//获取二级锁主列表
+ (void) requestSecondUserListWithLock_ID:(NSString *)lock_id
                        completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                             errorHandler:(void (^)(NSString *error))errorHandler;

//获取二级锁主下的子钥匙列表
+ (void) requestSecondChildKeyWithSecondID:(NSString *)client_id
                                   lock_id:(NSString *)lock_id
                         completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                              errorHandler:(void (^)(NSString *error))errorHandler;

//获取历史发送钥匙的手机号
+ (void) requestHistorySendKeysPhoneListWithClientID:(NSString *)client_id
                           completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler;

//是否公开锁主被申请权限
+ (void) isTheLockAllowdToBeApplyWithStatus:(NSString *)status
                                     lockID:(NSString *)lock_id
                          completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                               errorHandler:(void (^)(NSString *error))errorHandler;

//获取可被申请的锁/钥匙串列表
+ (void) requestAllowedToBeApplyLockListWIthMoblie:(NSString *)moblie
                                 completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                      errorHandler:(void (^)(NSString *error))errorHandler;

//发送申请钥匙请求
+ (void) requestApplyForKeysWithMoblie:(NSString *)moblie
                                 prict:(NSString *)price
                             startDate:(NSString *)startdate
                               endDate:(NSString *)endDate
                                lockid:(NSArray *)lock_id
                               message:(NSString *)message
                                  type:(NSString *)type
                     completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                          errorHandler:(void (^)(NSString *error))errorHandler;

//获取已经发送的申请记录
+ (void) requestHaveApplyedForKeyListWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                              errorHandler:(void (^)(NSString *error))errorHandler;

//获取申请钥匙消息列表
+ (void) requestApplyKeyMessageWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                        errorHandler:(void (^)(NSString *error))errorHandler;

//是否同意申请／撤销申请请求
+ (void) requestMasterIsAgreedWithKey_str:(NSString *)rsa_data
                                   AESkey:(NSString *)AESkey
                                    power:(NSString *)power
                             Command_code:(NSString *)Command_code
                               updatetime:(NSString *)updatetime
                                  news_id:(NSString *)news_id
                                   status:(NSString *)status
                        completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                             errorHandler:(void (^)(NSString *error))errorHandler;

//删除申请钥匙纪录
+(void) requestRemoveApplyKeyHidtoryWithNews_id:(NSString *)news_id
                              completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                   errorHandler:(void (^)(NSString *error))errorHandler;

//放弃锁主权限
+(void) requestGiveUpMasterPowerWithLockID:(NSString *)lock_id
                         completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                              errorHandler:(void (^)(NSString *error))errorHandler;

//是否有新的版本
+(void) requestIsHaveNewVesionWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                       errorHandler:(void (^)(NSString *error))errorHandler;

//删除钥匙后更新所有临时钥匙
+(void) requestUpdataAllTemporaryKeysWithPackageArr:(NSArray *)childPackages
                                  completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                       errorHandler:(void (^)(NSString *error))errorHandler;

//创建的钥匙串
+(void) requestKeyBrunchWithGroupName:(NSString *)group_name
                            lock_list:(NSArray *)lock_list
                    completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                         errorHandler:(void (^)(NSString *error))errorHandler;

//获取所有创建/发出的钥匙串
+(void) requestGetAllKeyBrunchWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                       errorHandler:(void (^)(NSString *error))errorHandler;

//是否允许其他人申请该钥匙串
+(void) requestAllowedKeysBrunchApplyedWithFrom_id:(NSString *)from_id
                                              type:(NSString *)type
                                            status:(NSString *)status
                                 completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                      errorHandler:(void (^)(NSString *error))errorHandler;

//获取该组内的所有锁
+(void) requestAllLocksOfBrunchWithID:(NSString *)ID
                                 type:(NSString *)type
                          completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                               errorHandler:(void (^)(NSString *error))errorHandler;

//编辑该组内的锁
+(void) requestEditCurrentBrunchWithGroup_id:(NSString *)group_id
                           completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler;

//保存该组内的锁
+(void) requestSaveCurrentBrunchWithGroup_id:(NSString *)group_id
                                    lockList:(NSMutableArray *)locklist
                           completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler;

//发送钥匙串（新）
+(void) new_requestSendLockGroupWithStyle:(NSString *)style
                                    power:(NSString *)power
                                lockinfor:(NSMutableArray *)lockinfor
                             Command_code:(NSString *)Command_code
                                 group_id:(NSString *)group_id
                                   mobile:(NSString *)mobile
                                  enddate:(NSString *)enddate
                                startdate:(NSString *)startdate
                               updatetime:(NSString *)updatetime
                                 totalfee:(NSString *)totalfee
                                  from_id:(NSString *)from_id
                                authorize:(NSString *)authorize
                        completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                             errorHandler:(void (^)(NSString *error))errorHandler;

//获取钥匙串的费用
+(void) getKeyGroupTotalFeeWithStartDate:(NSString *)startdate
                                 endDate:(NSString *)enddate
                                   style:(NSString *)style
                               authorize:(NSString *)authorize
                                group_id:(NSString *)group_id
                                   power:(NSString *)power
                       completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                            errorHandler:(void (^)(NSString *error))errorHandler;

//获取收到的钥匙串列表
+(void) getReceiveGroupBrunchListWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                       errorHandler:(void (^)(NSString *error))errorHandler;

//获取创建的/收到的钥匙串
+(void) getCreatAndReceivedGroupListWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                             errorHandler:(void (^)(NSString *error))errorHandler;

//修改钥匙串名称
+(void) editGroupBrunchNameWithGroup_id:(NSString *)group_id
                                   type:(NSString *)type
                             group_name:(NSString *)group_name
                      completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler;

//获取子钥匙的价格
+(void) getNewSendKeyTotalfeeWithStartdate:(NSString *)startdate
                                   enddate:(NSString *)enddate
                         completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                              errorHandler:(void (^)(NSString *error))errorHandler;

//向锁发送委托命令
+(void) sendCommondToLockWithLock_id:(NSString *)lock_id
                              mobile:(NSString *)mobile
                                 rsa:(NSString *)rsa
                              AESkey:(NSString *)AESkey
                                type:(NSString *)type
                             apptime:(NSString *)apptime
                        command_code:(NSString *)command_code
                           begintime:(NSString *)begintime
                             endtime:(NSString *)endtime
                               style:(NSString *)style
                          set_mobile:(NSString *)set_mobile
                   completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                        errorHandler:(void (^)(NSString *error))errorHandler;

//删除一把钥匙
+(void) delegateOneKeyWithKeyID:(NSString *)key_id
                           type:(NSString *)type
              completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                   errorHandler:(void (^)(NSString *error))errorHandler;

//取消一个用户的二级锁主权限  
+(void) cancelOneSeconMasterPowerWithLock_id:(NSString *)lock_id
                                      mobile:(NSString *)mobile
                                        type:(NSString *)type
                           completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler;

//数据同步
+(void) dataSynchronizationWithCompletionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                    errorHandler:(void (^)(NSString *error))errorHandler;

//删除钥匙串转发组
+(void) deleteAllLockBrunchWithGroup_transfer_id:(NSString *)group_transfer_id
                                            type:(NSString *)type
                               completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                    errorHandler:(void (^)(NSString *error))errorHandler;

//删除模板钥匙串
+(void) deleteUserDefineBrunchWithBrunch_id:(NSString *)brunch_id
                          completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                               errorHandler:(void (^)(NSString *error))errorHandler;

//同意一级/二级钥匙串的申请 RSA_AES','AESkey', 'news_id', 'power', 'Command_code','updatetime'
+(void) agreeTheKeyBrunchApplyedWithLockInfo:(NSMutableArray *)lockinfor
                                     news_id:(NSString *)news_id
                                       power:(NSString *)power
                                Command_code:(NSString *)Command_code
                                  updatetime:(NSString *)updatetime
                                      status:(NSString *)status
                           completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                errorHandler:(void (^)(NSString *error))errorHandler;

//获取所有委托命令列表
+(void) getAllCommandHistoryWithLock_id:(NSString *)lock_id
                      completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                           errorHandler:(void (^)(NSString *error))errorHandler;

//将手机号转化为用户id
+(void) phoneNumberChangeToUserIDWithPhoneNUm:(NSString *)phoneNumber
                            completionHandler:(void (^)(MKNetworkOperation *operation))completionHandler
                                 errorHandler:(void (^)(NSString *error))errorHandler;

//*********************** 2.0 新加 ********************
#pragma mark *****2.0 新增加******
+ (void) mkPOSTWithPath:(NSString *)path
             params:(NSDictionary *)parDic
    CompleteHandler:(void(^)(MKNetworkOperation *operation))completeHandler
           errorHandler:(void(^)(NSString *error))errorHandler;

/**1.设置手势密码*/
+ (void) setupGesturePassword:(NSString *)gesturePwd
                 successBlock:(void (^)(MKNetworkOperation *operation))success
                 failureBlock:(void(^)(NSString *err))failure;

/**2.修改手势密码*/
+ (void)modifyGesturePasswordWithOldPwd:(NSString *)old_pwd
                                new_pwd:(NSString *)new_pwd
                           successBlock:(void(^)(MKNetworkOperation *operation))success
                           failureBlock:(void(^)(NSString *error))failure;

/**3. 重置手势密码时,先验证登陆密码*/
+ (void)checkLoginpwdWhenResetGesturePasswordWithLoginpwd:(NSString *)loginpwd
                                               verifyCode:(NSString *)verifyCode
                                          completeHandler:(void(^)(MKNetworkOperation *operation))compleHandler
                                             errorHandler:(void(^)(NSString *error))errorHandler;
/**4.重置手势密码*/
+ (void)resetGesturePasswordWithNewpwd:(NSString *)new_password
                     completionHandler:(void(^)(MKNetworkOperation *operation))completeHandler
                          errorHandler:(void(^)(NSString *error))errorHandler;

/**5.验证手势密码*/
+ (void)verifyGesturePasswordWithPwd:(NSString *)pwd successBlock:(void(^)(id responObjc))success failureBlock:(void(^)(NSError *error))failure;



/**6.获取免密操作列表*/
+ (void)mianmiListGesturePasswordSuccessBlock:(void(^)(id responseObjc))success failureBlock:(void(^)(NSError *err))failure;


@end
